package com.chejianer.phone.controller;

import com.chejianer.phone.service.ExcelService;
import com.chejianer.phone.service.PhoneLinkService;
//import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class LoginController {

    @Autowired
    private PhoneLinkService phoneLinkService;

    @Autowired
    private ExcelService excelService;

    @RequestMapping(value = "login.do")
    public String loginPage() {
        return "login";
    }

    @RequestMapping(value = "phone.do")
    public String phonePage() {
        return "phone";
    }

    @RequestMapping(value = "accid.do")
    public String accidPage() {
        return "accid";
    }

    @RequestMapping(value = "/loginCheck.do")
    public ModelAndView loginCheck(HttpServletRequest request, LoginCommand loginCommand) {
            return new ModelAndView("main");
    }
    @RequestMapping(value = "/phoneLink.do" ,method = RequestMethod.POST)
    @ResponseBody
   /* public String phoneTest(@RequestBody PhoneCallReq phoneCallReq){
        String result=phoneLinkService.toLinkPhone(phoneCallReq.getCallerAcc(),phoneCallReq.getCaller(),phoneCallReq.getCallee());
        return result;
    }*/

    public String phoneTest(@RequestParam("callerAcc") String callerAcc,@RequestParam("caller") String caller,@RequestParam("callee") String callee){
        String result=phoneLinkService.toLinkPhone(callerAcc,caller,callee);
        return result;
    }

    @RequestMapping(value = "/createAccid.do" ,method = RequestMethod.POST)
    @ResponseBody
    public String crateAccid(@RequestParam("accid") String callerAcc){
        String result=phoneLinkService.toCreateAccid(callerAcc);
        return result;
    }
    @RequestMapping(value = "/outExcel.do" ,method = RequestMethod.POST)
    public void outExcel(HttpServletResponse response){
        excelService.toOutExcel(response);

    }

    private static class PhoneCallReq{
        private String callerAcc;
        private String caller;
        private String callee;

        public String getCallerAcc() {
            return callerAcc;
        }

        public String getCaller() {
            return caller;
        }

        public String getCallee() {
            return callee;
        }


        public void setCaller(String caller) {
            this.caller = caller;
        }

        public void setCallee(String callee) {
            this.callee = callee;
        }

        public void setCallerAcc(String callerAcc) {
            this.callerAcc = callerAcc;
        }
    }


}
